package com.zh.mycommon.util;

import java.nio.charset.StandardCharsets;

public class Fnv32aHash {
    // 计算字符串的哈希码值
    private static final int FNV_32_INIT = 0x811c9dc5;
    private static final int FNV_32_PRIME = 0x01000193;

    public static long hash(String s) {
        int hash = FNV_32_INIT;
        byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
        for (byte b : bytes) {
            hash ^= (b & 0xff);
            hash *= FNV_32_PRIME;
        }
        return hash & 0xFFFFFFFFL;
    }

}